package com.zkingsoft.services.distribution.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zkingsoft.dao.distribution.DisDesignerWorksDao;
import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.model.distribution.DisDesignerWorks;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.distribution.DisDesignerWorksService;
import com.zkingsoft.util.ModelUtils;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2017-06-26 07:15
 */
@Service("disDesignerWorksService")
public class DisDesignerWorksServiceImpl implements DisDesignerWorksService {

	@Autowired
	private DisDesignerWorksDao disDesignerWorksDao;

	@Override
	public int add(DisDesignerWorks disDesignerWorks) {

		return disDesignerWorksDao.insert(disDesignerWorks);

	}

	@Override
	public int batchAdd(List<DisDesignerWorks> disDesignerWorksList) {
		int num = 0;

		int c = 10000;
		int size = disDesignerWorksList.size() / c + 1;
		for (int i = 0; i < size; i++) {
			int begin = i * c;
			int end = (i + 1) * c;
			end = end >= disDesignerWorksList.size() ? disDesignerWorksList
					.size() : end;
			List<DisDesignerWorks> insertList = disDesignerWorksList.subList(
					begin, end);
			num += disDesignerWorksDao.batchInsert(insertList);
		}
		return num;

	}

	@Override
	public int modifyByMap(DisDesignerWorks oldDisDesignerWorks,
			DisDesignerWorks newDisDesignerWorks) {

		if (!ModelUtils.isModified(oldDisDesignerWorks, newDisDesignerWorks)) {
			return 1;
		}
		Map<String, Object> modifyMap = null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldDisDesignerWorks,
					newDisDesignerWorks);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("workId", oldDisDesignerWorks.getWorkId());
			disDesignerWorksDao.updateByMap(modifyMap);
		}
		return 1;
	}

	@Override
	public int modifyByModel(DisDesignerWorks disDesignerWorks) {

		return disDesignerWorksDao.updateByModel(disDesignerWorks);

	}

	@Override
	public int remove(List<Long> list) {

		return disDesignerWorksDao.deleteByIds(list);

	}

	@Override
	public int removeById(Long workId) {

		return disDesignerWorksDao.deleteById(workId);

	}

	@Override
	public int removeByModel(DisDesignerWorks disDesignerWorks) {

		return disDesignerWorksDao.deleteByModel(disDesignerWorks);

	}

	@Override
	public List<DisDesignerWorks> findInPage(DisDesignerWorks disDesignerWorks,
			PaginationVO pageVo) {

		return disDesignerWorksDao.selectInPage(disDesignerWorks, pageVo);

	}

	@Override
	public List<DisDesignerWorks> findByModel(DisDesignerWorks disDesignerWorks) {

		return disDesignerWorksDao.selectByModel(disDesignerWorks);

	}

	@Override
	public int findTotal(DisDesignerWorks disDesignerWorks) {

		return disDesignerWorksDao.selectTotalRecord(disDesignerWorks);

	}

	@Override
	public DisDesignerWorks findById(Long workId) {

		return disDesignerWorksDao.selectById(workId);

	}

}